Original Article · Articles in this issue
Heroku is an excellent application platform that I personally use for all my Ruby and Node projects. Their free tier is enough to accomplish pretty much any task, but it comes with one giant limitation: your app will go to sleep after an hour of inactivity.
When your app is asleep, the next user to access any of its resources will have to wait while the app spins up, resulting in a suboptimal user experience. Here are a few ways to get around this limitation and keep your Heroku app awake.
This is by far the easiest to implement. Just create a normal JavaScript setInterval that pings your app every 5 minutes. Place this is any file that’s executed in your app. I used Node’s http
library to do it:
var http = require("http");
setInterval(function() {
http.get("http://<your app name>.herokuapp.com");
}, 300000); // every 5 minutes (300000)
KeepAwake is a site that pings your free Heroku apps for you. All you have to do is enter your site’s name and URL and KeepAwake will send a GET request to it every 5 minutes.
Ironically, KeepAwake is a Heroku app itself. The only downside to this approach is that you’re reliant on this 3rd party service. If it goes down, your app will fall asleep.
If you install the NewRelic Heroku Addon you can set up availability monitoring. You provide a URL which NewRelic pings every 30 seconds, therefore keeping your app awake. The intended purpose of this feature is to alert you if your site goes down for business and performance reasons, but it has the added benefit of preventing your app from idling.